<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2008 Starbugs <univis2typo3@googlegroups.com>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

// DEFAULT initialization of a module [BEGIN]
unset($MCONF);
require ('conf.php');
require ($BACK_PATH.'init.php');
require ($BACK_PATH.'template.php');
$LANG->includeLLFile('EXT:univis2typo3/mod1/locallang.xml');
require_once (PATH_t3lib.'class.t3lib_scbase.php');
require_once (t3lib_extmgm::extPath('univis2typo3').'/mod1/conf.php');

$BE_USER->modAccess($MCONF,1);	// This checks permissions and exits if the users has no permission for entry.
	// DEFAULT initialization of a module [END]

// Configuration module include
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/class.configuration.php');

// Parser module include
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/parser/class.parser.php');


/**
 * Module 'Univis2Typo3' for the 'univis2typo3' extension.
 *
 * @author	Starbugs <univis2typo3@googlegroups.com>
 * @package	TYPO3
 * @subpackage	tx_univis2typo3
 */

class  tx_univis2typo3_module1 extends t3lib_SCbase {
    var $pageinfo;
    var $configuration;
    var $modFunctions = array(
	    'SortOrder',
	    'CreatePages',
	    'UnivISParser',
	    'function3',
    );


    /**
     * Initializes the Module
     * @return	void
     */
    function init()	{
	    global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;

	    parent::init();

	    $this->configuration = new Configuration();
	    $this->parser = new Parser();
	    /*
	    if (t3lib_div::_GP('clear_all_cache'))	{
		    $this->include_once[] = PATH_t3lib.'class.t3lib_tcemain.php';
	    }
	    */
    }

    /**
     * Adds items to the ->MOD_MENU array. Used for the function menu selector.
     *
     * @return	void
     */
    function menuConfig() {
	    global $LANG;
	    $this->MOD_MENU = array ( 'function' => array() );
	    foreach ($this->modFunctions as $param)
	    {
		$this->MOD_MENU['function'][ $param ] = $LANG->getLL( $param );
	    }
	    parent::menuConfig();
    }

    /**
     * Main function of the module. Write the content to $this->content
     * If you chose "web" as main module, you will need to consider the $this->id parameter which will contain the uid-number of the page clicked in the page tree
     *
     * @return	[type]		...
     */
    function main()	{
	    global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;

	    // Access check!
	    // The page will show only if there is a valid page and if this page may be viewed by the user
	    $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
	    $access = is_array($this->pageinfo) ? 1 : 0;

	    if (($this->id && $access) || ($BE_USER->user['admin'] && !$this->id))	{

			    // Draw the header.
		    $this->doc = t3lib_div::makeInstance('mediumDoc');
		    $this->doc->backPath = $BACK_PATH;
		    $this->doc->form='<form action="" method="POST">';

			    // JavaScript
		    $this->doc->JScode = '
			    <script language="javascript" type="text/javascript">
				    script_ended = 0;
				    function jumpToUrl(URL)	{
					    document.location = URL;
				    }
			    </script>
		    ';
		    $this->doc->postCode='
			    <script language="javascript" type="text/javascript">
				    script_ended = 1;
				    if (top.fsMod) top.fsMod.recentIds["web"] = 0;
			    </script>
		    ';

		    $headerSection = $this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />'.$LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.path').': '.t3lib_div::fixed_lgd_pre($this->pageinfo['_thePath'],50);

		    $this->content.=$this->doc->startPage($LANG->getLL('title'));
		    $this->content.=$this->doc->header($LANG->getLL('title'));
		    $this->content.=$this->doc->spacer(5);
		    $this->content.=$this->doc->section('',$this->doc->funcMenu($headerSection,t3lib_BEfunc::getFuncMenu($this->id,'SET[function]',$this->MOD_SETTINGS['function'],$this->MOD_MENU['function'])));
		    $this->content.=$this->doc->divider(5);


		    $this->printContent();

		    // Render content:
		    $this->moduleContent();

		    $this->content = '';

		    // ShortCut
		    if ($BE_USER->mayMakeShortcut())	{
			    $this->content.=$this->doc->spacer(20).$this->doc->section('',$this->doc->makeShortcutIcon('id',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']));
		    }

		    $this->content.=$this->doc->spacer(10);
	    } else {
		    // If no access or if ID == zero

		    $this->doc = t3lib_div::makeInstance('mediumDoc');
		    $this->doc->backPath = $BACK_PATH;

		    $this->content.=$this->doc->startPage($LANG->getLL('title'));
		    $this->content.=$this->doc->header($LANG->getLL('title'));
		    $this->content.=$this->doc->spacer(5);
		    $this->content.=$this->doc->spacer(10);
	    }

	    $this->content.=$this->doc->endPage();
    }

    /**
     * Prints out the module HTML
     *
     * @return	void
     */
    function printContent()	{
	    echo $this->content;
    }

    /**
     * Generates the module content
     *
     * @return	void
     */
    function moduleContent()	{
	    switch((string)$this->MOD_SETTINGS['function'])	{
		    case 'SortOrder':
			    $this->configuration->renderContent($this->id);
		    break;
		    case 'CreatePages':
			    $content='<div align=center><strong>Create Pages...</strong></div>';
			    $this->content.=$this->doc->section('Create Pages: To be implemented',$content,0,1);
		    break;
		    case 'UnivISParser':
			    $this->parser->renderContent();
		    break;
		    case 'function3':
			    $content='<div align=center><strong>Menu item #3...</strong></div>';
			    $this->content.=$this->doc->section('Message #3:',$content,0,1);
		    break;
	    }
    }
}



if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/univis2typo3/mod1/index.php'])	{
    include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/univis2typo3/mod1/index.php']);
}




// Make instance:
$SOBE = t3lib_div::makeInstance('tx_univis2typo3_module1');
$SOBE->init();

// Include files?
foreach($SOBE->include_once as $INC_FILE)	include_once($INC_FILE);

$SOBE->main();
$SOBE->printContent();

?>
